package com.siashan.toolkit.validation.validator;


import com.siashan.toolkit.core.util.StrUtil;
import com.siashan.toolkit.validation.PasswordEasy;
import com.siashan.toolkit.core.common.RegexPool;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * 密码校验
 *
 * @author siashan
 * @date 2023-12-02
 */
public class PasswordEasyValidator implements ConstraintValidator<PasswordEasy, String> {

    private String regexp = null;

    @Override
    public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
        return StrUtil.isEmpty(this.regexp) ? value.matches(RegexPool.PASSWORD_EASY) : value.matches(this.regexp);
    }


    @Override
    public void initialize(PasswordEasy constraintAnnotation) {
        this.regexp = constraintAnnotation.regexp();
    }
}
